﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace XSTDZ.ERP.Infrastructure.Authentication
{
    /// <summary>
    /// 验证类(基于ASP.NET MVC)
    /// </summary>
    public class Authenticate
    {
        private static bool _isRequireAuthencate;
        public Authenticate()
        {
            _isRequireAuthencate = false;
        }
        /// <summary>
        /// 是否进行验证
        /// </summary>
        public static bool IsRequireAuthentication
        {
            get { return _isRequireAuthencate; }
        }
        /// <summary>
        /// 用户是否是登陆
        /// </summary>
        /// <param name="controllerContext">ControllerContext上下文</param>
        /// <returns>bool</returns>
        public static bool IsAuthenticated(ControllerContext controllerContext)
        {
            
                return controllerContext.HttpContext.User.Identity.IsAuthenticated;
            
        }
        /// <summary>
        /// 是否不进行验证(若有的Action不需要验证，或所有权限都可以访问) //要解决对整个Controller 和 指定 Action
        /// </summary>
        public static bool IsAvoidAuthenticate(ControllerContext contextContext,IList<IAuthorizationFilter> authorizationList)
        { 
            bool isAvoidAuthenticate=false;
            foreach(var item in authorizationList)
            {
                if(item is AvoidAuthentication)
                {
                    isAvoidAuthenticate=true;
                    break;
                }
            }
            return isAvoidAuthenticate;
        }

        
    }
}
